/* File:        	Protocol.java
* Package:			org.esi.authz.common.comm
* Created:      	29-abr-2011
* Last Changed: 	0:10:45
* Author:       	Borja Urkizu borja.urquizu@tecnalia.com
*
*   
* History:
*  Revision 1.0.0.0  
* 
* Tecnalia Research and Innovation
*/
package com.tecnalia.authz.common.comm;

import java.io.Serializable;

import org.jboss.security.xacml.interfaces.RequestContext;
import org.jboss.security.xacml.interfaces.ResponseContext;

import com.tecnalia.authz.common.comm.error.IProtocolError;
import com.tecnalia.authz.common.comm.error.ProtocolErrorImpl;
import com.tecnalia.authz.common.comm.request.IRequestSerialized;
import com.tecnalia.authz.common.comm.request.RequestSerializedImpl;
import com.tecnalia.authz.common.comm.response.IResponseSerialized;
import com.tecnalia.authz.common.comm.response.ResponseSerializedImpl;
import com.tecnalia.comm.IProtocolData;
import com.tecnalia.comm.ProtocolDataImpl;

// TODO: Auto-generated Javadoc
/**
 * The Class Protocol.
 */
public class ProtocolImpl implements Serializable,IProtocol,IProtocolData,IProtocolError,IRequestSerialized,IResponseSerialized{	
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	private IProtocolData data = null;
	
	/** The request. */
	private IRequestSerialized request = null;

	/** The error. */
	private IProtocolError error = null;
	
	/** The response. */
	private IResponseSerialized response = null;
	
	/**
	 * Instantiates a new protocol.
	 */
	public ProtocolImpl(){
		request = new RequestSerializedImpl();
		error = new ProtocolErrorImpl();
		response = new ResponseSerializedImpl();
		data = new ProtocolDataImpl();
		
	}
	
	/**
	 * Instantiates a new protocol.
	 *
	 * @param id the id
	 * @param pepName the pep name
	 * @param queryMode the query mode
	 */
	public ProtocolImpl(int id, String pepName, int queryMode){
		request = new RequestSerializedImpl();
		error = new ProtocolErrorImpl();
		response = new ResponseSerializedImpl();
		data = new ProtocolDataImpl();
		
		this.setID(id);
		this.setName(pepName);
		request.setQueryMode(queryMode);
	}
	
	/* (non-Javadoc)
	 * @see com.tecnalia.authz.common.comm.IProtocol#setRequestSerializedImpl(com.tecnalia.authz.common.comm.request.IRequestSerialized)
	 */
	@Override
	public void setObjectInSerializedImpl(IRequestSerialized requestSerialized){
		request = requestSerialized;
	}
	
	/* (non-Javadoc)
	 * @see com.tecnalia.authz.common.comm.IProtocol#setProtocolErrorImpl(com.tecnalia.authz.common.comm.error.IProtocolError)
	 */
	@Override
	public void setProtocolErrorImpl(IProtocolError protocolError){
		error = protocolError; 
	}

	/* (non-Javadoc)
	 * @see com.tecnalia.authz.common.comm.IProtocol#setResponseSerializedImpl(com.tecnalia.authz.common.comm.response.IResponseSerialized)
	 */
	@Override
	public void setObjectOutSerializedImpl(IResponseSerialized responseSerialized){
		response = responseSerialized;
	}

	
	@Override
	public int getID() {
		return this.data.getID();
	}

	@Override
	public void setID(int ID) {
		this.data.setID(ID);
	}

	@Override
	public String getName() {
		return this.data.getName();
	}

	@Override
	public void setName(String name) {
		this.data.setName(name);
	}

	/* (non-Javadoc)
	 * @see org.esi.authz.common.comm.request.IRequestSerialized#getQueryMode()
	 */
	@Override
	public int getQueryMode() {
		return this.request.getQueryMode();
	}

	/* (non-Javadoc)
	 * @see org.esi.authz.common.comm.request.IRequestSerialized#setQueryMode(int)
	 */
	@Override
	public void setQueryMode(int queryMode) {
		this.request.setQueryMode(queryMode);
		
	}

	/* (non-Javadoc)
	 * @see org.esi.authz.common.comm.request.IRequestSerialized#serializeRequest(org.jboss.security.xacml.interfaces.RequestContext[])
	 */
	@Override
	public void serializeRequest(RequestContext[] request) {
		this.request.serializeRequest(request);		
	}

	/* (non-Javadoc)
	 * @see org.esi.authz.common.comm.request.IRequestSerialized#deserializeRequest()
	 */
	@Override
	public RequestContext[] deserializeRequest() {
		return this.request.deserializeRequest();
	}

	/* (non-Javadoc)
	 * @see org.esi.authz.common.comm.request.IRequestSerialized#LogRequest()
	 */
	@Override
	public void LogRequest() {
		this.request.LogRequest();		
	}

	/* (non-Javadoc)
	 * @see org.esi.authz.common.comm.response.IResponseSerialized#serializeResponse(org.jboss.security.xacml.interfaces.ResponseContext[])
	 */
	@Override
	public void serializeResponse(ResponseContext[] responseAuthz) {
		this.response.serializeResponse(responseAuthz);
	}
	
	/* (non-Javadoc)
	 * @see org.esi.authz.common.comm.response.IResponseSerialized#deserializeResponse()
	 */
	@Override
	public ResponseContext[] deserializeResponse() {
		return this.response.deserializeResponse();
	}

	
	/* (non-Javadoc)
	 * @see org.esi.authz.common.comm.error.IProtocolError#getError()
	 */
	@Override
	public int getError() {
		return this.error.getError();
	}

	/* (non-Javadoc)
	 * @see org.esi.authz.common.comm.error.IProtocolError#setError(int)
	 */
	@Override
	public void setError(int error) {
		this.error.setError(error);
	}

	/* (non-Javadoc)
	 * @see org.esi.authz.common.comm.error.IProtocolError#getErrorString()
	 */
	@Override
	public String getErrorString() {
		return this.error.getErrorString();
	}

	/* (non-Javadoc)
	 * @see org.esi.authz.common.comm.error.IProtocolError#setErrorString(java.lang.String)
	 */
	@Override
	public void setErrorString(String errorString) {
		this.error.setErrorString(errorString);	
	}


	/* (non-Javadoc)
	 * @see org.esi.authz.common.comm.error.IProtocolError#setInvalidIdName(int, java.lang.String)
	 */
	@Override
	public void setInvalidIdName(int ID, String name) {
		this.error.setInvalidIdName(this.getID(), this.getName());		
	}





}
